/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package zcam.main.web;

import java.io.PrintWriter;
import java.util.Locale;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springmodules.validation.commons.DefaultBeanValidator;

import egovframework.example.sample.service.EgovSampleService;
import egovframework.example.sample.service.SampleVO;
import egovframework.rte.fdl.property.EgovPropertyService;


/**  
 * @Class Name : EgovSampleController.java
 * @Description : EgovSample Controller Class
 * @Modification Information  
 * @
 * @  수정일      수정자              수정내용
 * @ ---------   ---------   -------------------------------
 * @ 2009.03.16           최초생성
 * 
 * @author 개발프레임웍크 실행환경 개발팀
 * @since 2009. 03.16
 * @version 1.0
 * @see
 * 
 *  Copyright (C) by MOPAS All right reserved.
 */

@Controller
@SessionAttributes(types=SampleVO.class)
public class LoginController {
	
	/** EgovSampleService */
    @Resource(name = "sampleService")
    private EgovSampleService sampleService;
    
    /** EgovPropertyService */
    @Resource(name = "propertiesService")
    protected EgovPropertyService propertiesService;

    /** Validator */
    @Resource(name = "beanValidator")
	protected DefaultBeanValidator beanValidator;
	
    /**
	 * 글 목록을 조회한다. (pageing)
	 * @param searchVO - 조회할 정보가 담긴 SampleDefaultVO
	 * @param model
	 * @return "/sample/egovSampleList"
	 * @exception Exception
	 */
    @RequestMapping(value="/main/login.do")
    public String login(Locale locale, Model model,
			HttpServletRequest request, HttpServletResponse response)
            throws Exception {
    	
    	JSONObject obj = new JSONObject();
    	
//    	obj.put("resultCode", request.getParameter("id"));
    	
    	String id = request.getParameter("id");
    	String password = request.getParameter("password");
    	
    	if(id.equals("admin") && password.equals("1234")){
    		obj.put("resultCode", "0");
    		obj.put("resultMessage", "로그인 성공...!!!");
    	}else{
    		obj.put("resultCode", "-1");
    		obj.put("resultMessage", "아이디가 존재하지 않습니다.");
    	}

		JSONArray list = new JSONArray();
		list.add("안녕하세요");
		list.add("테스트에 오신걸 환영 합니다.");
		list.add("앞으로 잘 부탁드립니다.");

		obj.put("messages", list);

		// model.addAttribute("obj", obj );

		try {

			response.setContentType("text/json; charset=utf-8");
			PrintWriter printWriter = response.getWriter();
			printWriter.print(obj.toString());
			printWriter.flush();
			printWriter.close();

		} catch (Exception ex) {
			System.out.println(">>>>> ERROR :: " + ex);
		}
        
        return "/sample/egovSampleList";
    } 

   
}
